home *** CD-ROM | disk | FTP | other *** search
- Path: po.CWRU.Edu!mab22
- From: mab22@po.CWRU.Edu (Michael A. Balfour)
- Newsgroups: comp.lang.c
- Subject: Re: Variant Records in C ... Is there a way ?
- Date: 4 Apr 1996 02:52:35 GMT
- Organization: Case Western Reserve University, Cleveland, OH (USA)
- Message-ID: <4jvdhj$mag@madeline.INS.CWRU.Edu>
- References: <Pine.OSF.3.91.960319170252.9783B-100000@alfa.ist.utl.pt> <315006F8.639@cmt.lpr.mail.carel.fi> <4iumf8$604@madeline.INS.CWRU.Edu> <danpop.827534657@rscernix> <4jcrbm$g5p@madeline.INS.CWRU.Edu> <828145096snz@genesis.demon.co.uk>
- Reply-To: mab22@po.CWRU.Edu (Michael A. Balfour)
- NNTP-Posting-Host: kanga.ins.cwru.edu
-
-
- In a previous article, fred@genesis.demon.co.uk (Lawrence Kirby) says:
-
- >In article <4jcrbm$g5p@madeline.INS.CWRU.Edu>
- > mab22@po.CWRU.Edu "Michael A. Balfour" writes:
- >
- >>
- >>In a previous article, danpop@mail.cern.ch (Dan Pop) says:
- >>
- >>>In <4iumf8$604@madeline.INS.CWRU.Edu> mab22@po.CWRU.Edu (Michael A. Balfour)
- >> writes:
- >>>
- >>>>*However*, if you feel like it, you can still do it yourself with some
- >>>>clever mallocs and overlaying structures. Not exactly elegant, but you
- >>>>can make it pretty memory-efficient.
- >>>
- >>>Not exactly blessed by the C standard, either :-)
- >>>
- >>
- >>Maybe not blessed, but it's certainly not condemned.
- >
- >You'll almost certainly invoke undefined behaviour as far as the language
- >is concerned. So it is in the same category as void main() or i = i++,
- >i.e. condemned to be non-portable.
- >
-
- You're willing to make a broad generalization, but you aren't backing it
- up with any substance. *Why* will it almost certainly invoke undefined
- behavior? You're allowed to treat memory like a series of bytes or
- chars, and that's *extremely* well-defined. Of course, treating it
- correctly is always up to the programmer, but there's no reason why a
- programmer will "almost certainly" do it wrong.
-
- In fact, it sounds like you agree with me a little later in your post:
-
- >The language does give license to access any object through character
- >lvalues. It has been suggested that future revisions of the standard will
- >clarify the issue so that, say copying an object as an array of unsigned char
- >works (as long as you end up with suitable alignment). Anyway this is a better
- >approach than using unions.
-
- See?
-
- >
- >That doesn't mean that ANSI C will guarantee that your code does what
- >you expect.
- >
-
- Of course not. In fact, relying on variables names to understand code
- doesn't always give you what you expect either. For that matter, if
- ANSI C *did* guarantee that my code does what I expect, I'd sell all my
- debugging tools today. :) All I was trying to say was that this (i.e.
- using memory as a series of bytes) was one solution to the problem if
- implemented correctly. And that unions were not a solution, because the
- original poster specified that they were trying not to use the extra
- filler-byte memory that unions require.
-
- Mike Balfour
-
- --
- ----------------------------------+--------------------------------
- Mike Balfour, Partner | BS/MS Graduate - ECMP
- Overload Engineering | Case Western Reserve University
- "New Ideas for a Brighter Future" | Cleveland, OH
-